
//
//  HTWelComeController.swift
//  weibo
//
//  Created by JonsonLiu on 16/4/20.
//  Copyright © 2016年 liujonson. All rights reserved.
//

import UIKit
import SDWebImage
class HTWelComeController: UIViewController {

    
    
    override func viewDidLoad() {
        super.viewDidLoad()


        setUpUI()
        
    }

    
    
  
    
 
    private func setUpUI(){
    
        view.backgroundColor = UIColor(white: 247/255.0, alpha: 1)
        
        view.addSubview(messageLable)
        view.addSubview(headImage)
        
        headImage.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.centerX.equalTo(view)
            make.top.equalTo(200)
        }
        
        
        messageLable.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImage)
            make.top.equalTo(headImage.snp_bottom).offset(15)
        }
    }
    
    
    //更新约束
    
    
    //设置约束
    

    private lazy var messageLable : UILabel = {
    
        let lable = UILabel()
        
        lable.text = "欢迎滚回来"
        
        lable.textColor = UIColor.darkGrayColor()
        

        return lable
    }()
    
    
    private lazy var headImage: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        imageView.layer.cornerRadius = 40
        imageView.layer.masksToBounds = true

        
        let viewModel = HTViewModel.sharedViewModel
        
        if let userImage = HTViewModel.sharedViewModel.account?.avatar_large {
        
            imageView.sd_setImageWithURL(NSURL(string: userImage), placeholderImage: UIImage(named: "avatar_default_big"))
        }
        
        return imageView
    }()
    
    
    
    //设置动画效果
    override func viewDidAppear(animated: Bool) {
        
        super.viewWillAppear(animated)
        
        //更新约束
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(100)
            
        }
        
        
        //执行弹簧动画
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                
                UIView.animateWithDuration(1, animations: { () -> Void in
                    self.messageLable.alpha = 1
                    }, completion: { (_) -> Void in
                        
                        // 切换控制器
                        let  appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
                        
                        appDelegate?.window?.rootViewController = HTMainTController()
            
                        print("动画执行完毕")
                })
        }
    }
    
    
    
    //懒加载image
//     lazy var headImage : UIImageView = {
//        
//        let  imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
//        imageView.layer.cornerRadius = 45
//        imageView.layer.masksToBounds = true
//        return imageView
//        
//    }()
}
